Category Archives: .NET

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 IIS Microsoft

Register asp.net in IIS 10

run as admin

 
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>dism /online /enable-feature /featurename:IIS-ASPNET45

might need to enable this extensions:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319/dism /online /enable-feature /featurename:IIS-ApplicationDevelopment
C:\Windows\Microsoft.NET\Framework64\v4.0.30319/dism /online /enable-feature /featurename:IIS-ISAPIFilter
C:\Windows\Microsoft.NET\Framework64\v4.0.30319/dism /online /enable-feature /featurename:IIS-ISAPIExtensions
C:\Windows\Microsoft.NET\Framework64\v4.0.30319/dism /online /enable-feature /featurename:IIS-NetFxExtensibility45

C:\Windows\Microsoft.NET\Framework64\v4.0.30319/dism /online /enable-feature /featurename:IIS-ASPNET45
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 .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>
Code Snippets .NET VB

Dynamically Generate and Display Barcode Image in ASP.Net

n this article I will explain how to dynamically generate and display barcode image using ASP.Net in C# and VB.Net languages.
 
Barcode Font
First you will need to download the Free Barcode Font from the following URL
Once downloaded follow the following steps.
1. Extract the ZIP file.
2. Click and Execute INSTALL.exe file.
3. After installation is completed restart your machine.



 

<form id="form1" runat="server">
<asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
<asp:Button ID="btnGenerate" runat="server" Text="Generate" onclick="btnGenerate_Click" />

<hr />

<asp:PlaceHolder ID="plBarCode" runat="server" />
</form>




 


 
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO

 

 


Protected Sub btnGenerate_Click(sender As Object, e As EventArgs)
    Dim barCode As String = txtCode.Text
    Dim imgBarCode As New System.Web.UI.WebControls.Image()
    Using bitMap As New Bitmap(barCode.Length * 40, 80)
        Using graphics__1 As Graphics = Graphics.FromImage(bitMap)
            Dim oFont As New Font("IDAutomationHC39M", 16)
            Dim point As New PointF(2.0F, 2.0F)
            Dim blackBrush As New SolidBrush(Color.Black)
            Dim whiteBrush As New SolidBrush(Color.White)
            graphics__1.FillRectangle(whiteBrush, 0, 0, bitMap.Width, bitMap.Height)
            graphics__1.DrawString("*" & barCode & "*", oFont, blackBrush, point)
        End Using
        Using ms As New MemoryStream()
            bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
            Dim byteImage As Byte() = ms.ToArray()
 
            Convert.ToBase64String(byteImage)
            imgBarCode.ImageUrl = "data:image/png;base64," & Convert.ToBase64String(byteImage)
        End Using
        plBarCode.Controls.Add(imgBarCode)
    End Using
End Sub

 

 

 

 

https://www.aspsnippets.com/Articles/Dynamically-Generate-and-Display-Barcode-Image-in-ASPNet.aspx

.NET ASP.Net 2.0 IIS

The page was not displayed because the request entity is too large. iis7

“The page was not displayed because the request entity is too large.”

 

I think this will fix the issue IF you have SSL enabled:

Setting uploadReadAheadSize in applicationHost.config file on IIS7.5 would resolve your issue in both cases. You can modify this value directly in applicationhost.config.

1) Select the site under Default Web Site

2) Select Configuration Editor

3) Within Section Dropdown, select “system.webServer/serverRuntime”

4) Enter a higher value for “uploadReadAheadSize” such as 1048576 bytes. Default is 49152 bytes.

During client renegotiation process, the request entity body must be preloaded using SSL preload. SSL preload will use the value of the UploadReadAheadSize metabase property, which is used for ISAPI extensions

Reference: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/7e0d74d3-ca01-4d36-8ac7-6b2ca03fd383.mspx?mfr=true

 

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 .NET

Programmatically set the selected menu item in the Menu control

Mnu1.Items(1).Selected = True
Mnu1.FindItem(&quot;Nutrients&quot;).Selected = True
mnu1.Items(indexToSelect).Selected = True
MenuItem mi = this.Menu1.FindItem(&quot;Home&quot;);
 mi.Selected = true;
this.Menu1.Items[0].Selected = true;
Code Snippets .NET VB

Get First and last word from sentence

        Dim Nome As String = &quot;Carlos Galhano&quot;
        Dim firstword As String = Nome.Substring(0, Nome.IndexOf(&quot; &quot;))
        Dim lastWord As String = Nome.Substring(Nome.LastIndexOf(&quot; &quot;c) + 1)
        Response.Write(&quot;first: &quot; &amp; firstword &amp; &quot; Last: &quot; &amp; lastWord)