C# Code Is:
var fromAddress = new MailAddress("unbroken4420@gmail.com", "Zihadul");
var toAddress = new MailAddress("rajon5000@gmail.com", "Rajon");
const string fromPassword = "*******";
const string subject = "Subject";
const string body = "Body";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
Wednesday, January 10, 2018
Saturday, January 6, 2018
Base URL For Sub-domain Folder
Set on Muster Page or Layout page:
<div id="BaseUrl" data-baseurl="@Context.Request.Url.GetLeftPart(UriPartial.Authority)@Url.Content("~/")"></div>
JS:
var rootFolder = $("#BaseUrl").data("baseurl");
var route =rootFolder+'/api/ApplicationMenu/Get';
<div id="BaseUrl" data-baseurl="@Context.Request.Url.GetLeftPart(UriPartial.Authority)@Url.Content("~/")"></div>
JS:
var rootFolder = $("#BaseUrl").data("baseurl");
var route =rootFolder+'/api/ApplicationMenu/Get';
Enabling session state in Web API
Create two classes; SessionControllerHandler and SessionHttpControllerRouteHandler. Implement as follows:
public
class
SessionControllerHandler : HttpControllerHandler, IRequiresSessionState
{
public
SessionControllerHandler(RouteData routeData)
:
base
(routeData)
{ }
}
public
class
SessionHttpControllerRouteHandler : HttpControllerRouteHandler
{
protected
override
IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return
new
SessionControllerHandler(requestContext.RouteData);
}
}
In your WebApiConfig, add the following above your route declaration(s):
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
var httpControllerRouteHandler = typeof(HttpControllerRouteHandler).GetField("_instance",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
if (httpControllerRouteHandler != null)
{
httpControllerRouteHandler.SetValue(null,
new Lazy<HttpControllerRouteHandler>(() => new SessionHttpControllerRouteHandler(), true));
}
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
Now Session is On
HttpContext.Current.Session["ForLeftMenu"] = "Rajon";
if (HttpContext.Current.Session["ForLeftMenu"] != null)
{
string text = HttpContext.Current.Session["ForLeftMenu"].ToString();
}
Tuesday, January 2, 2018
Setup dotLess CSS In ASP.NET MVC Project (Minify js/cs file)
Improve performance for dotLess files in MVC projectBundles are an easy way to merge and minify resources in your application (such as JavaScript files and CSS stylesheets). Using “System.Web.Optimization.Less” plugin, you can improve site performance in a better way.
So go back to Package Manager Console and install the below plugin:
PM> Install-Package System.Web.Optimization.Less
And add your bundle to the appropriate location within BundleConfig.cs,
So, this LessBundle gives you the facility to combine and minify files while running the application in <compilation debug="false" /> mode, and it takes care of transforming LESS code into CSS. It does not require updating the layout every time you add a new file to the project.
So go back to Package Manager Console and install the below plugin:
PM> Install-Package System.Web.Optimization.Less
And add your bundle to the appropriate location within BundleConfig.cs,
- public class BundleConfig
- {
- public static void RegisterBundles(BundleCollection bundles)
- {
- // NOTE: existing bundles are here
- bundles.Add(new LessBundle("~/Content/less").Include("~/Content/*.less"));
- }
- }
Subscribe to:
Posts (Atom)