Archive for tag: ASP.NET

ASP.NET forms authentication keeps displaying login page on iPad

ASP.NET forms authentication keeps displaying login page on iPad, when I was developing iPad web app, I have come across one of the bug that once we "Add as Home Screen" then we can create Web as App then once you have logged in then when we try and go through website somewhere it automatically clears the session out so then I have found out the solution, that we need to make changes inside web.config file and I had my my web.config file as following:

<authentication mode="Forms">
  <forms loginurl="/Account/LogOn" />
</authentication>

 Then, I have found out, and I have added timeout="2880" cookieless="UseCookies" as following: 

<authentication mode="Forms">
  <forms loginurl="/Account/LogOn" timeout="2880" cookieless="UseCookies" />
</authentication>

and it will start getting it working and you will not loose session.

If you have question don't forget to ask.

Thank you for going through

Convert Text into Image using C#

Hi there,

I was thinking to do something interesting about embedding fonts to a website. I was trying to embed fonts in website then I thought of converting Text into image here below you can convert the text into image.

    private Bitmap CreateBitmapImage(string TextImage)
    {
        Bitmap objBmp = new Bitmap(1, 1);

        int Width = 0;

        int Height = 0;

        // Create the Font object for the image text drawing.

        Font objFont = new Font("Arial", 20, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);

        // Create a graphics object to measure the text's width and height.

        Graphics objGraphics = Graphics.FromImage(objBmp);

        // This is where the bitmap size is determined.

        Width = (int)objGraphics.MeasureString(TextImage, objFont).Width;

        Height = (int)objGraphics.MeasureString(TextImage, objFont).Height;

        // Create the bmpImage again with the correct size for the text and font.

        objBmp = new Bitmap(objBmp, new Size(Width, Height));

        // Add the colors to the new bitmap.

        objGraphics = Graphics.FromImage(objBmp);

        // Set Background color

        objGraphics.Clear(Color.White);

        objGraphics.SmoothingMode = SmoothingMode.AntiAlias;

        objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;

        objGraphics.DrawString(TextImage, objFont, new SolidBrush(Color.FromArgb(102, 102, 102)), 0, 0);

        objGraphics.Flush();

        return (objBmp);
    }

 

If you like this article, please don't forget to like and share with people.

Enjoy your day.

Text to Speech in ASP.NET with C#

Hi there,

I hope you guys had nice week, Its Saturday wasn't working but when I was having bath and thought of doing something interesting then I was working during the week on text to speech and thought of doing simplest and smallest code for text to speech. I'll go through in step by step in below section:

 

Step 1: Just create website.

 

Step 2: In the website just creates one page or you will already have default.aspx in side it, we have to create on text box in which person can write any text, also a button to click once you finish entering text and it will enable windows speech libraries. Please write following code to start with inside default.aspx.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Text to speach</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtspeech" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="clickToSpeech" runat="server" Text="Speech" OnClick="clickToSpeech_Click" />
    </div>
    </form>
</body>
</html>

 

Step 3: Right click to solution explorer of the visual studio and add reference of SpeechLibrary. In the reference dialog box select the COM tab and add the "Microsoft Speech Object Library" and click ok. Now you will see in the references folder of your solution explorer "SpeechLib".

 

Step 4: And in code behind of Default.aspx which is Default.aspx.cs file, copy the following code.

using System;
using SpeechLib;

namespace Text_to_speech
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void clickToSpeech_Click(object sender, EventArgs e)
        {
            SpVoice objspeach = new SpVoice();
            objspeach.Speak(txtspeech.Text.Trim(), SpeechVoiceSpeakFlags.SVSFDefault);
            objspeach.WaitUntilDone(System.Threading.Timeout.Infinite);
        }
    }
}

 

Step 5: Now run the code

And enter the text that you want and hit speech then you will listen the text

 

It was good weekend day for me to write little bit of brief explanation of text to speech.

If you like article, please don't forget to share or like this article.

Thank you

Potentially Dangerous Request.Form Value Was Detected From The Client

Hi Everyone,

I was trying to create new RichTextEditor in one of my project and was using textarea or <asp:Textbox ……> and it has some of the scripts that I needed to use and then what happened was that I couldn't do it because it had an script and some of the Html elements so then I got error like "Potentially Dangerous Request.Form Value Was Detected From The Client" here below is an error:

First-Step

To deal with this you have to disable ValidationRequest feature. You have to disable this because validation is done by ASP.NET while executing code by disabling it will not validate, means will not check for scripts and html into inputted script. <%@Page directives ValidationRequest="false", Or you can disable it for enter application from web.config file. 

<configuration>
    <system.web>
        <pages validateRequest="false" />
    </system.web>
</configuration>

 If you are running on .NET framework 4.0 make sure you have to add requestValidationMode as well

<configuration>
    <system.web>
        <httpRuntime requestValidationMode="2.0" />
    </system.web>
</configuration>

Then it would solve your problem and it has solved my problem as well.

I hope it would have solved your issue if you looking for same issue. Also, don't forget to share and like on social media.

Thank you,

Data binding not binding after submit or page refresh C#.NET or VB.NET

Today,

I have started building application and stuck in problem.

I have bind data with Repeater using DataTable it was binding on first Page_Load but when I hit submit button, it was calling another method which called repeater and getting user selection from it. But Repeater that I was getting was empty.

Then I have figured it out that EnableViewState was false, so I have added that in @Page directives EnableViewState="true". or can change from the web.config in to system.web in pages section as below:

<system.web>
   <pages enableViewState="true"  />
</system.web>

Again, I have tried running code but it didn't work for me. Then I did some trial and error for it the I have fingured it out that I didn't write on Page_Load event that it shouldn't be PostBack. So I have written following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace ExampleOfRepeaterBinding
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //Repeater binding code
            }
        }
    }
}

 

If you think that helped you please don't forget to rate and share via Facebook, Twitter, etc.

Enjoy you day and have nice weekends.