Category Archives: ASP.Net

ASP.Net IIS

Install ASP.NET 4.5 in Windows 8 and Windows Server 2012

The Aspnet_regiis.exe utility is no longer used for installing and uninstalling ASP.NET 4.5 in Windows 8. ASP.NET 4.5 is now a Windows component and can be installed and uninstalled just like any other Windows component.

To install or uninstall ASP.NET 4.5 in Windows 8 or Windows Server 2012, use one of the following options:

  • Run the following command from an administrative command prompt: Console
dism /online /enable-feature /featurename:IIS-ASPNET45

For Windows 8 client computers, turn on IIS-ASPNET45 in Turn Windows Features On/Off under Internet Information Services > World Wide Web Services > Application Development Features > ASP.NET 4.5.

For Windows Server 2012 computers, enable IIS-ASPNET45 using Server Manager, under Web Server (IIS) > Web Server > Application Development > ASP.NET 4.5.

https://learn.microsoft.com/en-us/troubleshoot/developer/webapps/aspnet/www-administration-management/install-aspnet-45-windows-8-server-2012
Code Snippets .NET ASP.Net Microsoft VB

How can i get information in Network Payload using vb.net?

I receive information from another page from a payment gateway. On the admin panel i can assign the callback url to notify me.

it will respond with a json payload.

How to get this info in codebehind on Page_load?

Make sure that, if you are using Friendly urls that the callback url has no .aspx

and try something like:

Public Shared Function GetRequestBody() As String
    Dim bodyStream = New IO.StreamReader(HttpContext.Current.Request.InputStream)
    bodyStream.BaseStream.Seek(0, SeekOrigin.Begin)
    Dim _payload = bodyStream.ReadToEnd()
    Return _payload
End Function

thanks to https://stackoverflow.com/questions/71097260/how-can-i-get-information-in-network-payload-using-c

Related: yfdFO, ClNoTe, kNzZPM, nsVX, KGukN, YRBMY, IoS, jrSbB, tIKr, OsfYa, xlAe, CwpRV, reKj, jiL, zDUOQ,
.NET ASP.Net ASP.Net 2.0 Microsoft

Problem with Session in iFrame after windows update

Microsoft ASP.NET will now emit a SameSite cookie header when HttpCookie.SameSite value is “None” to accommodate upcoming changes to SameSite cookie handling in Chrome. As part of this change, FormsAuth and SessionState cookies will also be issued with SameSite = ‘Lax’ instead of the previous default of ‘None’, though these values can be overridden in web.config.

You have to set the cookieSameSite= “None” in the session state tag to avoid this issue. I have tried this and working well.

<system.web>
<sessionState cookieSameSite="None"  cookieless="false" timeout="360">
</sessionState> 
</system.web>

https://social.msdn.microsoft.com/Forums/en-US/1b99630c-299c-446e-bf4b-d7d4d74bf9ef/problem-with-session-in-iframe-after-recent-windows-update?forum=aspstatemanagement

Code Snippets .NET ASP.Net

Tamanho máximo de upload asp.net

we.config

<configuration>
  ...
  <system.web>
    ...
    <httpRuntime maxRequestLength="1048576"/>
    ...
  </system.web>
  ...
  </system.webServer>
    ...
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
    </security>
    ...
  </system.webServer>
  ...
</configuration>

set to 1 gigabyte

maxAllowedContentLength -> bytes;
maxRequestLength -> kilobytes.

Code Snippets ASP.Net IIS

SSL Redirect URL, rewrite rule

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.webServer>
	<rewrite>
		<rules>
			<rule name="Redirect to http" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
				<match url="*" negate="false" />
				<conditions logicalGrouping="MatchAny">
					<add input="{HTTPS}" pattern="off" />
				</conditions>
				<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
			</rule>
		</rules>
	</rewrite>
  </system.webServer>
</configuration>

read more »

Code Snippets .NET ASP.Net

UnobtrusiveValidationMode requires a ScriptResourceMapping for ‘jquery’ – Asp.NET

erro:

Erro de Servidor no Aplicativo '/'.

WebForms UnobtrusiveValidationMode requer um ScriptResourceMapping para 'jquery'. Adicione um jquery nomeado de ScriptResourceMapping (diferencia maiúsculas de minúsculas).

Descrição: Ocorreu uma exceção sem tratamento durante a execução da atual solicitação da Web. Examine o rastreamento de pilha para obter mais informações sobre o erro e onde foi originado no código. 



Adicionar no web.config

 <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
  </appSettings><span style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" data-mce-type="bookmark" class="mce_SELRES_start"></span>
ASP.Net Microsoft

Datetime format / Globalization

<pre class="default prettyprint prettyprinted"><code><span class="tag"><configuration>
</span><span class="tag"><system.web>
</span><span class="tag"><globalization</span><span class="atn">culture</span><span class="pun">=</span><span class="atv">"en-GB"</span><span class="tag">/>
</span><span class="tag"></system.web>
</span><span class="tag"></configuration></span></code></pre>
Code Snippets .NET ASP.Net regex

ASP.Net Character Length Regular Expression Validators

ASP.Net RegularExpression Validators

Maximum character length Validation (Maximum 6 characters allowed)

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator1"
Display = "Dynamic"
ControlToValidate = "TextBox1"
ValidationExpression = "^[\s\S]{0,6}$"
ErrorMessage="Maximum 6 characters allowed.">
</asp:RegularExpressionValidator>

Minimum character length Validation (Minimum 6 characters required)

<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator2"
Display = "Dynamic"
ControlToValidate = "TextBox2"
ValidationExpression = "^[\s\S]{6,}$"
ErrorMessage="Minimum 6 characters required.">
</asp:RegularExpressionValidator>

Minimum and Maximum character length Validation (Minimum 2 and Maximum 6 characters required)

<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator3"
Display = "Dynamic"
ControlToValidate = "TextBox3"
ValidationExpression = "^[\s\S]{2,6}$"
ErrorMessage="Minimum 2 and Maximum 6 characters required.">
</asp:RegularExpressionValidator>

Alphanumeric with special Characters
Minimum length 7 and Maximum length 10. Characters allowed – a – z A – Z 0-9 ’@ & # .

<asp:RegularExpressionValidator ID="RegExp1" runat="server"
ErrorMessage="Password length must be between 7 to 10 characters"
ControlToValidate=" txtPassword "
ValidationExpression="^[a-zA-Z0-9'@&#.\s]{7,10}$" />

Alphanumeric Only
Minimum length 7 and Maximum length 10. Characters allowed – a – z A – Z 0-9

<asp:RegularExpressionValidator ID="RegExp1" runat="server"
ErrorMessage="Password length must be between 7 to 10 characters"
ControlToValidate=" txtPassword "
ValidationExpression="^[a-zA-Z0-9\s]{7,10}$" />

Alphabets Only
Minimum length 7 and Maximum length 10. Characters allowed – a – z A – Z

<asp:RegularExpressionValidator ID="RegExp1" runat="server"
ErrorMessage="Password length must be between 7 to 10 characters"
ControlToValidate="txtPassword"
ValidationExpression="^[a-zA-Z]{7,10}$" />

Numeric Only
Minimum length 7 and Maximum length 10. Characters allowed – 0 – 9

<asp:RegularExpressionValidator ID="RegExp1" runat="server"
ErrorMessage="Password length must be between 7 to 10 characters"
ControlToValidate="txtPassword"
ValidationExpression="^[0-9]{7,10}$" />

source:
http://www.aspsnippets.com/Articles/ASP.Net-Regular-Expression-Validator-to-validate-Minimum-and-Maximum-Text-Length.aspx

Code Snippets ASP.Net

Concatenate data fields as binding expression

Concatenate data fields as binding expression:

&lt;asp:label id=&quot;Label1&quot; runat=&quot;server&quot; 
     text='&lt;%# String.Format(&quot;{0}, {1}&quot;, Eval(&quot;ContactLastName&quot;), Eval(&quot;ContactFirstName&quot;)) %&gt;'&gt;
&lt;/asp:label&gt; 

how to implemented mailto in Hyperlink asp control inside the gridview:

&lt;asp:HyperLink id=&quot;hl1&quot; runat=&quot;server&quot; 
   NavigateUrl='&lt;%# Eval(&quot;Email&quot; , &quot;mailto:{0}&quot;) %&gt;'
   Text='&lt;%# Eval(&quot;Email&quot;) %&gt;'&gt;
&lt;/asp:HyperLink&gt;
ASP.Net

Using “Cache” in ASP.Net

 Data can be stored on the client – using the view state of the page, or on the server in a variable session state or application, or using the server cache.
ASP.NET implements System.Web.Caching.Cache class to store objects that require a large amount of server resources to be created, so that they do not have to be recreated each time it is needed.
You can access via code information about a class instance cache through the property cache, the object of the HttpContext or Page object.
Expiration policy for items in cache:
  • Specific time:  absolute expiration
  • May also expire if not accessed for a period of time:  sliding expiration

read more »