Tuesday, March 27, 2018

Delete a key from registry - Permission denied issue

get psexec is available from Microsoft here

And then go to the folder of psexec and run following command. 
psexec -i -d -s c:\windows\regedit.exe

It will open regedit. then set the permisison in there and then you can delete. 


Thursday, March 8, 2018

Flush IIS Logs in Real Time

Use following command to flush IIs Logs in real time without 60 seconds wait.

netsh http flush logbuffer

can run following command in background 

while true; do netsh http flush logbuffer > /dev/null; sleep 1; done &

and then tail
tail -100f u_ex130814.log

Tuesday, March 6, 2018

Trace WCF communication in Fiddler

Add following in your web.config file. makes sure that fiddler proxy port (8888) is correct. (in Tools --> Options --> Connections)

<system.net>
<defaultProxy>
<proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://127.0.0.1:8888" />
</defaultProxy>
</system.net>

Monday, February 26, 2018

Thursday, February 22, 2018

Async Await support for Console Applications

Nito.AsyncEx is the library which can be used to add support for Console application. (not limited to console application.)
Add the nuget package - Nite.AsyncEx

And then call your function as

AsyncContext.Run(() => ExecuteMethodAsync());

private static async Task ExecuteMethodAsync()
{
//do something
}

Happy Coding!

Thursday, February 15, 2018

Sample Code to open PDF File in Browser instead of download



public HttpResponseMessage Get(int id)
{
try
{
string filename = "File.pdf";
string filepath = System.Web.HttpContext.Current.Server.MapPath("~") + "/" + filename;
byte[] filedata = System.IO.File.ReadAllBytes(filepath);
string contentType = MimeMapping.GetMimeMapping(filepath);

HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(filedata); ;
result.Content.Headers.ContentType = new MediaTypeHeaderValue(MimeMapping.GetMimeMapping(filepath));
var cd = new System.Net.Mime.ContentDisposition
{
FileName = filename,
Inline = true,
};

HttpContext.Current.Response.Headers.Add("Content-Disposition", cd.ToString());
return result;

}
catch (Exception)
{
throw new HttpResponseException(HttpStatusCode.InternalServerError);
}
}

Converting a guest user to member in Azure AD

To convert a guest user into a member in Azure Ad run the following command.


Connect-MsolService
login with Global admin of the AD in which guest user exists.

Get-MsolUser -UserPrincipalName hpatel#EXT#@yourdomain.onmicrosoft.com -UserType Member

This should convert the user to member.
hpatel#EXT#@yourdomain.onmicrosoft.com is the guest user. remember Microsoft adds #EXT# to the email. so if you get error that says that user not found, run the following command and validate the upn.
Get-MsolUser --UnlicensedUserOnly