Feeds:
Posts
Comments

In asp.net we can’t change form’s action attribute in html markup by simply putting the page name . By default it takes default.aspx as form’s action. If you are using IIS 7 url rewriting module and want to solve canonical issue then IIS7 default behaviour creates problem such as when you type url like http://www.abc.com/ and click home link in website then it displays url as http://www.abc.com/default.aspx and this will create problem for google to rank your website.

To solve this problem you have to override FORM action attribute.

reference from code project for code

Just create a class in the app_code folder, and copy and paste the following lines:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text.RegularExpressions;

public class cdsnetFormActionModifier : Stream
{
    private Stream _sink;
    private long _position;
    string _url;
    public cdsnetFormActionModifier(Stream sink, string url)
    {
        _sink = sink;
        _url = "$1" + url + "$3";
    }

    public override bool CanRead
    {
        get { return true; }
    }

    public override bool CanSeek
    {
        get { return true; }
    }

    public override bool CanWrite
    {
        get { return true; }
    }

    public override long Length
    {
        get { return 0; }
    }

    public override long Position
    {
        get { return _position; }
        set { _position = value; }
    }

    public override long Seek(long offset, System.IO.SeekOrigin direction)
    {
        return _sink.Seek(offset, direction);
    }

    public override void SetLength(long length)
    {
        _sink.SetLength(length);
    }

    public override void Close()
    {
        _sink.Close();
    }

    public override void Flush()
    {
        _sink.Flush();
    }

    public override int Read(byte[] buffer, int offset, int count)
    {
        return _sink.Read(buffer, offset, count);
    }

    public override void Write(byte[] buffer, int offset, int count)
    {
        string s = System.Text.UTF8Encoding.UTF8.GetString(buffer, offset, count);
        Regex reg = new Regex("(<form.*action=\")([^\"]*)" + 
                              "(\"[^>]*>)", RegexOptions.IgnoreCase);
        Match m = reg.Match(s);
        if (m.Success)
        {
            string form = reg.Replace(m.Value, _url);
            int iform = m.Index;
            int lform = m.Length;
            s = s.Substring(0, iform) + form + s.Substring(iform + lform);
        }
        byte[] yaz = System.Text.UTF8Encoding.UTF8.GetBytes(s);
        _sink.Write(yaz, 0, yaz.Length);
    }
}


after creating this class use its method to override in your pageload event of Default.aspx


protected void Page_Load(object sender, EventArgs e)
{
    this.Response.Filter = 
      new cdsnetFormActionModifier(this.Response.Filter, "your_url");
}

public string CapitalIntials(string name)
{
return new CultureInfo(“en”).TextInfo.ToTitleCase(name.ToLower());
}

Using this markup you can check whether user’s browser has javascript enabled or not

<noscript>

<meta http-equiv=”Refresh” content=”0; url=noJavascriptPage.html”>

</noscript>

If user has not enabled javasript , you can redirect him to other page

Its very common problem every web developer has to face that is re-submitting data on page refresh (F5).

You will find lots of solution whiling googling but some of them are very lengthy and some are very confusing. I found very easy and effective way of handling this problem.

Using session[] and viewstate[]

On page load take one session variable and store system current date time

if (!IsPostBack)
{
Session[“Refresh”] = Server.UrlDecode(System.DateTime.Now.ToString());
}
On Button click event check whether session and viewstate are same value or not, If same then do your login

if (Session[“Refresh”].ToString() == ViewState[“Refresh”].ToString())
{

[  Do your coding  here ]

Session[“Refresh”] = Server.UrlDecode(System.DateTime.Now.ToString());
}
else
{
response.write(“You have refreshed the page”)
}

Write one Page pre render event to assing session value in viewstate  like this
protected void Page_PreRender(object sender, EventArgs e)
{
ViewState[“Refresh”] = Session[“Refresh”];
}

Thats all….happy coding

 

 

F:\image.jpg=exefile

disable contextmenu

For disabling right click on image use this attribute in body tag

<body oncontextmenu=”return false”>

disable image toolbar

Use this markup to disable image toolbar for all the images in the page

<meta http-equiv=”imagetoolbar” content=”no” />

For individual image use this markup

<img src=”image.jpg” gallerying=”no” />


Follow

Get every new post delivered to your Inbox.