[Route("movies/released/{year}/{month:regex(\\d{4}):range (1,12)}")]

System.InvalidOperationException: The inline constraint resolver of type 'DefaultInlineConstraintResolver' was unable to resolve the following inline constraint: 'range (1,12)'.

I'm getting an error while viewing it on web.

I have the following in my razor view:

@model Product

 <form ...>
     ...
     <div class="form-group">
       <label asp-for="Description"></label>
          <textarea asp-for="Description" class="form-control" cols="20" rows="3">Why is this default value disappearing?</textarea>
     </div>
     ...
  </form>

For some unknown magic, the default textarea value disappear.

I'm trying to save a list of items to a database. The code looks like following.

dbContext.MySet.AddRange(list);
dbContext.SaveChanges();

However, I get a following exception:

System.Data.Entity.Infrastructure.DbUpdateException occurred HResult=0x80131501 Message=Entities in 'DbContext.MySet' participate in the 'QueryTransaction' relationship. 0 related 'Query' were found. 1 'Query' is expected. Source=EntityFrameworkBlockquote

Any ideas what might couse the trouble?

I want every time button click new linkbutton create but every time i create a new linkbutton replace previous. How can i achieve this. Button is on different web page and linkbutton should create on different webpage.

I have a partial View content a bootstrap table (sonTable), and i have other View content other bootstrap table (FatherTable).

I tried to display the contents of table (sonTable) in table (FatherTable) detail but without success.

SonTable

<table id="GetSuiviProduction"
           data-toggle="table">
        <thead>
            <tr>
                <th data-field="NomProd">NomProd</th>
                <th data-field="DateDebut">DateDebut</th>
                <th data-field="DateFin">DateFin</th>
                <th data-field="DateCreation">DateCreation</th>
                <th data-field="QteRebus">QteRebus</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                var IdForm = "form" + item.Id;
                @Html.HiddenFor(model => model.Where(c => c.Id == item.Id).First().Id)
                @Html.HiddenFor(model => model.Where(c => c.Id == item.Id).First().NomProd)
                <tr>

                    @Html.AntiForgeryToken()
                    <td>
                        <form></form>
                        <form method="post" id="@IdForm" action="@Url.Action("Edit", "Suivi_Production")"></form>
                        @item.NomProd
                    </td>

                    <td>
                        <div class="col-md-10">
                            @Html.TextBoxFor(model => model.Where(c => c.Id == item.Id).First().DateDebut, new { @class = "form-control", form = IdForm })
                        </div>
                    </td>
                    <td>
                        <div class="col-md-10">
                            @Html.TextBoxFor(model => model.Where(c => c.Id == item.Id).First().DateFin, new { @class = "form-control", form = IdForm })
                        </div>
                    </td>
                    <td>
                        <div class="col-md-10">
                            @Html.TextBoxFor(model => model.Where(c => c.Id == item.Id).First().DateCreation, new { @class = "form-control", form = IdForm })
                        </div>
                    </td>
                    <td>
                        <div class="col-md-10">
                            @Html.TextBoxFor(model => model.Where(c => c.Id == item.Id).First().QteRebus, new { @class = "form-control", form = IdForm })
                        </div>
                    </td>
                    <td>
                        <div class="form-group">
                            <div class="col-md-offset-2 col-md-10">
                                @Html.HiddenFor(model => model.Where(c => c.Id == item.Id).First().Id, new { form = IdForm })
                                @Html.HiddenFor(model => model.Where(c => c.Id == item.Id).First().NomProd, new { form = IdForm })
                                <input type="submit" value="Create" form="@IdForm" class="btn btn-default" />
                            </div>
                        </div>
                    </td>
                </tr>
            }
        </tbody>
    </table>

FatherTable

<table id="GetSuiviProduction"
       data-toggle="table"
       data-url="@Url.Action("GetOrderFabric", "Suivi_Production")"
       data-toolbar="#get"
       data-pagination="true"
       data-side-pagination="server"
       data-page-list="[5, 10, 20, 50, 100, 200]"
       data-search="true"
       data-height="400"
       data-query-params="queryParams"
       data-show-refresh="true"
       data-detail-view="true"
       data-detail-formatter="detailFormatter">
    <thead>
        <tr>
            <th data-field="Statut">Statut</th>
            <th data-field="Votre_Commande">Votre_Commande</th>
            <th data-field="Date_Commande">Date_Commande</th>
            <th data-field="Numero_Doc">Numero_Doc</th>
            <th data-field="Nomenclature">Nomenclature</th>
            <th data-field="Designation">Designation</th>
            <th data-field="Quantite">Quantite</th>
            <th></th>
        </tr>
    </thead>
</table>

Part of my application needs to create PDF reports with charts and tables. Some of the tables are quite wide, and so i think it would be best if they were outputted on separate landscape orientated pages, while the rest of the PDF is in portrait orientation. I'm using Rotativa and don't think it is capable of outputting both portrait and landscape pages within the same PDF.

Are there any tools/ways of doing this?

Uploading photos to instagram, using webrequest c#? you can help me.

I am using stripe.net for making payments in asp.net. I ran into a problem. I couldn’t update the metadata of the charge retrieved, although I was able to retrieve the charge from stripe as per the documentation on stripe.net. However updating a charge is not mentioned in the documentation. Any help would be much appreciated. Here is the code that I am using

var chargeService = new StripeChargeService(newgenSecretKey);

//successfully retrieves the charge
StripeCharge charge = chargeService.Get("py_1AXfkAJsBBkng4KEnulfiR7I");

//Metadata is not getting updated
charge.Metadata = myDict;

The following code does not update the Meta Data in the dashboard. Apart from this, there is another option of StripeChargeUpdateOptions but I am not sure how this was intended to work. There is not documentation in github as well. Unlike the StripeChargeService which take in the stripe secret key as argument,StripeChargeUpdateOptions does not take any. I tried using this without any luck. But I think this is what I have to use because for a charge you can only update 4 parameters including metadata and StripeChargeUpdateOptions has only those. I was wondering if anyone out there could help me with this.

The following code is what I tried

var chargeServiceupdate = new StripeChargeUpdateOptions();
chargeServiceupdate.Metadata = myDict;

PS : MyDict is a dictionary and I tried using it when creating a charge. Meta data is succesfully being set. Cannot do the same when I retrieve a charge and try to set it.

When the user changes their password, they get Logged Out from the app. However, if they are logged into another app at the same time they remain logged in on the other app.

I want to log out the user from all apps they are logged into when they change their password.

In browser we check the user cookie by this code

Provider = new CookieAuthenticationProvider
{
    // Enables the application to validate the security stamp when the user logs in.
    // This is a security feature which is used when you change a password or add an external login to your account.  
    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
        validateInterval: TimeSpan.FromSeconds(1),
        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}

Is there are same code to web api?

I have a task for my project to connect to ASP.NET SignalR websocket to fetch some data in real-time from Ruby program. The problem is I couldn't find any single SignalR client for Ruby. As I understand, SignalR version of websockets is a bit different from e.g. socket.io, there are some instances called "Hubs", so I guess special client is needed.

Can I connect to SignalR websocket from Ruby using any existing solutions, or do I need to write client from scratch?

I can't resolve this error:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 79.10.34.109:9100

I have a asp.NET c# page that send a socket to the ip (79.10.34.109) which has the 9100 port open. I test from another pc and the problem is not the port fowarding or the host becouse it works all perfect. So, I create an asp.NET application that send the same socket that i tested but it can't see the host. the socket.Connect() method catch and error. You can see it here:

Link WebPage Error

This is my code that i use. It perfectly work on other machine but if i use an asp.net application it dosen't work:

        public void TestPrint() {

    Socket clientSock = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);
    clientSock.NoDelay = true;
    IPAddress ip = IPAddress.Parse("79.10.34.109");
    IPEndPoint remoteEP = new IPEndPoint(ip, 9100);
    clientSock.Connect(remoteEP); //crash
    Encoding enc = Encoding.ASCII;

    // Line feed hexadecimal values
    byte[] bEsc = new byte[4];
    bEsc[0] = 0x0A;
    bEsc[1] = 0x0A;
    bEsc[2] = 0x0A;
    bEsc[3] = 0x0A;

    // Send the bytes over 
    clientSock.Send(bEsc);

    string output = "some text;

    char[] array = output.ToCharArray();
    byte[] byData = enc.GetBytes(array);
    clientSock.Send(byData);
    clientSock.Close();}

What is the problem?

I host the project on aruba

Today, I'm facing a weird issue in form designing. I'm using bootstrap 3 and in my HTML code I've assigned row class to various divs. Issue I'm facing is two divs having same class are behaving differently.

<form class="form-horizontal" id="frmcreatebank" role="form">
     <div class="row">
        <div class="col col-sm-6 form-group-sm">
            <div class="form-group" style="text-align:left;">
                <label class="col-sm-5" for="BANKROUTENO">
                      BANKROUTE NO :
                </label>
            <div class="col-sm-7 form-group">
                      @Html.TextBox("TXT_BANKROUTENO", null, null, new { @class = "form-control validate[required] minSize[9] number", maxLength = 9, data_width = "100%" })
            </div>
      </div>
  </div>
  <div class="col col-sm-6 form-group-sm">
      <div class="form-group" style="text-align:left;">
          <label class="col col-sm-5" for="BANKNAME">
                BANK NAME :
          </label>
      <div class="col-sm-7">
      <div class="form-group">
          @Html.TextBox("TXT_BANKNAME", null, null, new { @class = "form-control validate[required]", maxLength = 50 })
      </div>
 </div>
 </div>
 </div>
 </div>
 <div class="row">
     <div class="col col-sm-4 form-group-sm">
        <div class="form-group" style="text-align:left;">
            <label class="col col-sm-5" for="ADD1">
                  ADDRESS(1) :
            </label>
        <div class="col col-sm-7">
            @Html.TextBox("TXT_ADD1", null, null, new { @class = "form-control validate[required]", maxLength = 50 })
        </div>
     </div>
     </div>
     <div class="col col-sm-4 form-group-sm">
         <div class="form-group" style="text-align:left;">
             <label for="ADD2" class="col col-sm-5">
                  ADDRESS(2) :
             </label>
         <div class="col col-sm-7">
             @Html.TextBox("TXT_ADD2", null, null, new { @class = "form-control", maxLength = 50 })
         </div>
     </div>
     </div>
     <div class="col col-sm-4 form-group-sm">
         <div class="form-group" style="text-align:left;">
             <label class="col col-sm-5" for="ADD3">
                   ADDRESS(3) :
             </label>
         <div class="col col-sm-7">
             @Html.TextBox("TXT_ADD3", null, null, new { @class = "form-control", maxLength = 50 })
         </div>
     </div>
     </div>
     </div>
     <div class="row">
         <div class="col col-sm-4 form-group-sm">
            <div class="form-group" style="text-align:left;">
                <label class="col col-sm-5" for="PINCODE">
                     PINCODE :
                </label>
            <div class="col col-sm-7">
                @Html.TextBox("TXT_PINCODE", null, null, new { @class = "form-control validate[required] minSize[6] number", maxLength = 6 })
            </div>
      </div>
 </div>
  <div class="col col-sm-4 form-group-sm">
      <div class="form-group">
          <label class="col col-sm-5" for="CITY">CITY :</label>
          <div class="col col-sm-7">
             @Html.DropDownList("DDL_CITY", new SelectList(ViewBag.TypeList, "CODE", "LONGDESC"), "-- Select City --", new { @class = "selectpicker validate[required]", data_width = "100%" })
           </div>
       </div>
   </div>
   <div class="col col-sm-4 form-group-sm">
       <div class="form-group" style="text-align:left;">
           <label class="col col-sm-5" for="EMAIL">
                 EMAIL :
           </label>
        <div class="col col-sm-7">
    <div class="form-group">
        @Html.TextBox("TXT_EMAIL", null, new { @class = "form-control validate[required,custom[email]]" })
    </div>
    </div>
    </div>
    </div>
        </div>
   <div class="row">
   <div class="col col-sm-4 form-group-sm">
       <div class="form-group" style="text-align:left;">
           <label class="col col-sm-5" for="TELEPHONE1">
                 TELEPHONE(1) :
           </label>
       <div class="col col-sm-7">
           <div class="form-group">
              @Html.TextBox("TXT_TELEPHONE1", null, new { @class = "form-control validate[required] number", maxLength = 12 })
           </div>
       </div>
       </div>
       </div>
         <div class="col col-sm-4 form-group-sm">
             <div class="form-group" style="text-align:left;">
                 <label class="col col-sm-5" for="TELEPHONE2">
                       TELEPHONE(2) :
                 </label>
              <div class="col col-sm-7">
                  <div class="form-group">
                      @Html.TextBox("TXT_TELEPHONE2", null, new { @class = "form-control number", maxLength = 12 })
                  </div>
              </div>
          </div>
      </div>
   <div class="col-sm-4 form-group-sm">
      <div class="form-group" style="text-align:left;">
          <label class="col col-sm-5" for="MOBILE">
                MOBILE :
          </label>
       <div class="col col-sm-7">
     <div class="form-group">
         @Html.TextBox("TXT_MOBILE", null, new { @class = "form-control number", maxLength = 10 })
      </div>
      </div>
      </div>
      </div>
      </div>
  </form>

Issue here is there is a lot of gap between two rows.

Problem is stated in this screenshot.enter image description here

Here as you can see there is too much gap between first row and second row. I want this gap to be same as gap between second row and third row.

Any help will be appreciated.

This is an MVC razor page, that works fine on first load. If I use a reload from javascript or even a refresh in the browser menu (Chrome), I get Server Error in '/' Application.

>The view 'actionChangeUserSentence' or its master was not found or no view 
>engine supports the searched locations. The following locations were searched:
>~/Views/Conduct/actionChangeUserSentence.aspx
>~/Views/Conduct/actionChangeUserSentence.ascx
>~/Views/Shared/actionChangeUserSentence.aspx
>~/Views/Shared/actionChangeUserSentence.ascx
>~/Views/Conduct/actionChangeUserSentence.cshtml
>~/Views/Conduct/actionChangeUserSentence.vbhtml
>~/Views/Shared/actionChangeUserSentence.cshtml
>~/Views/Shared/actionChangeUserSentence.vbhtml
> and so on...

meaning the url string is considered a non MVC url. I tried several possibilities to reload, including:

-location.reload();
-window.location.reload(false); with both false and true
-location.href = location.href;
-history.go(0);

By the way, the reason I need to refresh is that js drawing on a html canvas doesn't work except after full page (re)load, reason still unknown. But anyway, a browser menu refresh should of course always work, I guess... Thanks for any help.

Currently I have a web api that gets the file from the ftp server and write it to memory stream. Then the api returns it to the client. It's working when I'm downloading files that has kilobytes. But the problem is when I'm downloading like 1mb or up. the response from the api returns a different file size than the original file size.

Here is the API

            try
            {
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["ftpServerRPM"] + filename);
            request.Method = WebRequestMethods.Ftp.DownloadFile;
            request.UseBinary = true;
            request.Proxy = null;
            request.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["ftpUsername"], ConfigurationManager.AppSettings["ftpPassword"]);
                FtpWebResponse _response = (FtpWebResponse)request.GetResponse();
                Stream responseStream = _response.GetResponseStream();

                var memoryStream = new MemoryStream();
                byte[] byteBuffer = new byte[bufferSize];
                int bytesRead = responseStream.Read(byteBuffer, 0, bufferSize);

                try
                {
                    while (bytesRead > 0)
                    {
                        memoryStream.Write(byteBuffer, 0, bytesRead);
                        bytesRead = responseStream.Read(byteBuffer, 0, bufferSize);
                    }
                }
                catch (Exception ex)
                {
                    response.StatusCode = HttpStatusCode.InternalServerError;
                    return response;
                }

                response.Content = new ByteArrayContent(memoryStream.GetBuffer());
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = filename
                };

                response.StatusCode = HttpStatusCode.OK;

                _response.Close();
                responseStream.Close();

and here is the angular.service.

return this._http.post('file/attachments/' + attachment.Id, { headers: this._headers })
.map((res: any) => new Blob([res._body], { type: "application/octet-stream" })).subscribe(data => {
            var filename = attachment.fileName;
            var contentType = "application/octet-stream";

            var linkElement = document.createElement('a');
            try {
                var blob = new Blob([data], { type: contentType });
                var url = window.URL.createObjectURL(blob);
                linkElement.setAttribute('href', url);
                linkElement.setAttribute("download", filename);

                var clickEvent = new MouseEvent("click", {
                    "view": window,
                    "bubbles": true,
                    "cancelable": false
                });
                linkElement.dispatchEvent(clickEvent);
            } catch (ex) {
                console.log(ex);
            }
        }
        );/*.catch(this.handleError);*/

Size in API: Length = 1536839.

Size in client = size:2290952

The document was downloaded but its content is blank. Other file type was corrupted.

Any idea why did this happen?

Thanks in advance!

I am trying to centre an asp button in the very centre of a div. I have managed to centre the button horizontally and vertically, but not at the same time. I have been through several other similar questions yet none of the solutions work for me.

        <div class="container" style="border: solid red 1px;">
        <div class="row">
            <span class="col-md-3 Suggestions">Feel free to send any suggestions to the site</span>
            <asp:TextBox ID="Suggestions" CssClass="Suggestions col-md-7 suggestionsBox" runat="server">Enter your suggestions here</asp:TextBox>
            <div class="text-center col-md-2 suggestionsSubmitParent">
                <asp:Button runat="server" CssClass="suggestionsSubmit" Text="Submit" ID="btnSubmit" />
            </div>
        </div>
        <div class="row">
            <span class="col-md-3 suggestionsName">Please enter your name</span>
            <asp:TextBox ID="SuggestionsName" CssClass="col-md-7 suggestionsName" runat="server">Enter your suggestions here</asp:TextBox>

        </div>
    </div>

CSS

.Suggestions {
    text-align:center;
    margin-top: 15px;   
}

.suggestionsBox {
    height: 140px;
}
.suggestionsName{
    margin-top:10px;
}

.suggestionsSubmit {
    width: 80px;
}
.suggestionsSubmitParent {
    height: 155px;
    display: flex;
    align-items: center;

I am trying to use Google Fonts in my .NET website. This is proving incredibly difficult and not as simple as I expected.

In my CSS I am of course adding the correct google style. But it is not rendering when launching the website.

I have tried using Googles Nugget package, as well as just adding the css url like you are supposed to in the header.

I tried researching this, but found almost zero questions. So this is probably something super simple that my tired programming brain can't think of.

Any help?

I have a Web application that needs to know the physical path to a different application. The only way I know is to use the Microsoft.Web.Administration API and do something like:

var server = new ServerManager();
var path = server.Sites["Site Name"]
    .Applications["Application Name"]
    .VirtualDirectories["Directory"]
    .PhysicalPath;

However, this won't work if the running process doesn't have permission to read from C:\windows\system32\inetsrv\config. I get the error:

Message: Filename: redirection.config

Error: Cannot read configuration file due to insufficient permissions

Stack trace: at Microsoft.Web.Administration.Interop.IAppHostAdminManager.GetAdminSection(String bstrSectionName, String bstrPath)

at Microsoft.Web.Administration.Configuration.GetSectionInternal(ConfigurationSection section, String sectionPath, String locationPath)

.....

Is there any other way to retrieve this information?

I am trying to display a loading gif while my datatable is being loaded on my server. I found some code from here, but when i try and implement it I get the Runtime error 'Show' is undefined. Below is my javascript/jquery code i am using

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function ShowProgress() {
    setTimeout(function () {
        var modal = $('<div />');
        modal.addClass("modal");
        $('body').append(modal);
        var loading = $(".loading");
        loading.show();
        var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
        var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
        loading.css({ top: top, left: left });
    }, 200);
}
$('form').live("submit", function () {
    ShowProgress();
});

My div id is loading, so when it encounters the loading.show() in the javascript, it errors out.

<div class="loading" align="center">
    Loading. Please wait.<br />
         <br />
         <img src="gears.gif" alt="" />
        </div>

And I am registering my script on the page load event like:

 If IsPostBack = False Then
        Dim script As String = "$(document).ready(function () { $('[id*=Button2]').click(); });"
        ClientScript.RegisterStartupScript(Me.GetType, "load", script, True)

    End If

Any help would be appreciated.

I've made a typo while creating the controller class of my web application and now my URL looks like this: /Blogs/postname. And i wanted it to look like this: /Blog/postname or better yet /blog/postname.

I tried RegisterRoutes in Global.asax.cs:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.MapMvcAttributeRoutes();

    routes.MapRoute(
        "BlogPage",
        "blog/{action}/{id}",
        new { controller = "Blogs", action = "Index", id = "" }
    );

    routes.MapRoute(
       "Default",
       "{controller}/{action}/{id}",
       new { controller = "Blogs", action = "Index", id = "" }
   );
}

protected void Application_Start()
{
    RouteConfig.RegisterRoutes(RouteTable.Routes);
}

But when i try to navigate to localhost:######/blog i get an 404 error. I want to know if there's a way to fix this without having to start all over again.

How to get a variable value from a json object after deserialization?

Example below:

Data

{
    "test": "test_data",
    "visible": true,
    "other": "test 2"
}

HTML

@{
    var data = Newtonsoft.Json.JsonConvert.DeserializeObject(Model.Value);

    ??? data["other"]???
}

I want to get the value that belongs to the key other.