Posts

Image to base 64 conversion in asp.net

public string ImageToBase64(string ImgUrl)         {             string base64ImageRepresentation = "";             try             {                 string Imgpath = HttpContext.Current.Server.MapPath("~/AdvertisementImages/") + ImgUrl;                 byte[] imageArray = System.IO.File.ReadAllBytes(Imgpath);                 imageArray = System.IO.File.ReadAllBytes(Imgpath);                 base64ImageRepresentation = Convert.ToBase64String(imageArray);             }             catch (Exception ex)             {                 return base64ImageRepresentation;     ...

base 64 string To image conversion with compression in asp.net

public bool Base64ToImage(string imgUrl, string img)         {             string fileName = imgUrl + ".png";             bool Result = false;             byte[] image = Convert.FromBase64String(img);             string Imgpath = HttpContext.Current.Server.MapPath("~/Temp/") + fileName;             try             {                 System.IO.File.WriteAllBytes(Imgpath, image);                 Bitmap bmp1 = new Bitmap(HttpContext.Current.Server.MapPath("~/Temp/") + fileName);                 ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);                 System.Drawing.Imaging.Encoder myEncoder =System.Drawing....

redirect page when no page found (error code 404) in asp.net

in web.config <configuration> <system.web>     <customErrors defaultRedirect="default.aspx" mode="On">       <error statusCode="404" redirect="page-error.aspx"/>     </customErrors> </system.web> </configuration>

url rewriting (http to https binding) in asp.net

in web.config <configuration> <system.webServer>     <rewrite>       <rules>         <rule name="HTTP to HTTPS redirect" stopProcessing="true">           <match url="(.*)" />           <conditions>             <add input="{HTTPS}" pattern="off" ignoreCase="true" />           </conditions>           <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"               redirectType="Permanent" />         </rule>       </rules>       <outboundRules>         <rule name="Add Strict-Transport-Security when HTTPS" enabled="true">           <match serverVariable="RESPONSE_Strict_Transport_Sec...