Category Archives: Code Snippets

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,
Code Snippets Active Directory PowerShell

Using Net User command to Display User Expiration Date

Net user USERNAME /domain

Using Powershell

get-aduser -filter * -properties passwordlastset, passwordneverexpires |ft Name, passwordlastset, Passwordneverexpires

To display the expiration date rather than the password last set date, use this command.

Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} –Properties "DisplayName", "msDS-UserPasswordExpiryTimeComputed" |
Select-Object -Property "Displayname",@{Name="ExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}


Code Snippets Exchange Microsoft PowerShell

Hide Office 365 Groups from the GAL

Schools may require that newly created classes are hidden from the Global Address List (GAL) in Exchange Online. Classes may be hidden through PowerShell. Use the instructions below to hide Classes created with SDS from the GAL.

Classes are represented in Office 365 as Office 365 Groups. In Exchange Online, where the GAL is built, they are called Unified Groups. Use the Get/Set-UnifiedGroup cmdlet to manage these groups through PowerShell.

 

Hide a single class

Launch PowerShell as an Administrator and connect to Exchange Onlineas shown below.

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking

Once connected, run the command below against the Group you want to hide.

Set-UnifiedGroup -Identity <UnifiedGroupIdParameter> -HiddenFromAddressListsEnabled $true 

 

Hide all classes created by SDS

Launch PowerShell as an Administrator and connect to Exchange Online as shown below.

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking

Once connected, run the command below against all SDS-created groups.

 $Groups = Get-UnifiedGroup -ResultSize Unlimited | ? {$_.PrimarySmtpAddress -like "Section_*"}
Foreach ($Group in $Groups) {Set-UnifiedGroup -Identity $Group.Name -HiddenFromAddressListsEnabled $true}
}

 

 

https://docs.microsoft.com/en-us/schooldatasync/hide-office-365-groups-from-the-gal

Code Snippets SQL Server

Query to list number of records in each table in a database


SELECT SCHEMA_NAME(schema_id) AS [SchemaName],
[Tables].name AS [TableName],
SUM([Partitions].[rows]) AS [TotalRowCount]
FROM sys.tables AS [Tables]
JOIN sys.partitions AS [Partitions]
ON [Tables].[object_id] = [Partitions].[object_id]
AND [Partitions].index_id IN ( 0, 1 )
-- WHERE [Tables].name = N'name of the table'
GROUP BY SCHEMA_NAME(schema_id), [Tables].name;

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 Active Directory

Using PowerShell To List All Users Password Expiration Date

get-aduser -filter * -properties passwordlastset, passwordneverexpires |ft Name, passwordlastset, Passwordneverexpires

export to csv

 

 get-aduser -filter * -Properties passwordlastset, passwordneverexpires, displayName,Enabled,givenName,sn,distinguishedname,mail,mailnickname,mobile,telephoneNumber,facsimileTelephoneNumber,title | select displayName,passwordlastset, Passwordneverexpires, Enabled,givenName,sn,distinguishedname,mail,mailnickname,mobile,telephoneNumber,facsimileTelephoneNumber,title | export-csv "c:\20190904_ADUsers4.csv" -NoTypeInformation
 

How to Get AD Users Password Expiration Date

Code Snippets Networking

Enable/disable firewall from command line

psexec \\pcname netssh firewall set opmode disable

Get PsTools:
https://docs.microsoft.com/en-us/sysinternals/downloads/pstools

more info:

Enable/disable firewall from command line

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 IIS

IIS: Redirect to another domain

Redirect from any page of www.mysite1.com to a static root of another site www.mysite2.com

 

<rule name="site2.com" stopProcessing="true">
             <match url=".*" />
             <conditions>
                 <add input="{HTTP_HOST}" pattern="^(.*)?site1.com" />                 
             </conditions>
             <action type="Redirect" url="http://www.site2.com/{R:0}" />
</rule>
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 »